const router = require('koa-router')()
const db = require('../config/db')

router.get('/', async (ctx, next) => {
  var sqlSelect = "select * from list"
  var result = await db.query(sqlSelect, [])
  var chapterList = result;
  await ctx.render('index', {
    list: chapterList
  })
})

router.get('/detail', async (ctx, next) => {
  var chapterId=ctx.params.id
  console.log(chapterId)
  var selectSql="select * from list where chapterId=?"
  var result=await db.query(selectSql,[chapterId])
  await ctx.render('detail',{
    chapter:result[0]
  })
})

router.get('/json', async (ctx, next) => {
  ctx.body = {
    title: 'koa2 json'
  }
})


module.exports = router
